<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>租金提醒列表 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">所属机构</div>
                    <div class="field">
                        <input name="buOrgCd" id="buOrgCd" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">所属省公司</div>
                    <div class="field">
                        <input name="cstMgrOrgCd" id="cstMgrOrgCd" placeholder="请选择" type="text" class="ui-textbox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">预约时间</div>
                    <div class="field">
                        <input ligerui="width: 82" name="startAppoDt" id="startAppoDt" type="text" class="ui-datepicker"
                               value="">
                        -
                        <input ligerui="width: 82" name="endAppoDt" id="endAppoDt" type="text" class="ui-datepicker"
                               value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">应还时间</div>
                    <div class="field">
                        <input ligerui="width: 82" name="startPayDts" id="startPayDts" type="text" class="ui-datepicker"
                               value="">
                        -
                        <input ligerui="width: 82" name="endPayDts" id="endPayDts" type="text" class="ui-datepicker"
                               value="">
                    </div>
                </div>
              <div class="fieldBox" id="searchPrjTypCdId">
						<div class="label">项目类型</div>
						<div class="field">
							<select name="prjTypCd" id="prjTypCd">
								<option value="  " selected="selected">--请选择--</option>
								<c:forEach items="${projectTypeList}" var="opt">
									<option value="${opt.key}">${opt.value}</option>
								</c:forEach>
							</select>
						</div>
					</div>

					<div class="fieldBox" id="searchInsCodeId" <sys:resourceAuth resCd="noThdOrg">style="display: none" </sys:resourceAuth>>
						<div class="label">第三方机构</div>
						<div class="field">
							<select name="insCode" id="insCode">
								<option value="  " selected="selected">--请选择--</option>
								<c:forEach items="${friBaseList}" var="fri">
									<option value="${fri.insCode}">${fri.fundRasInsNm}</option>
								</c:forEach>
							</select>
						</div>
					</div>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                    <span id="appoBtn" class="sq-button sq-button-round">预约</span>
                    <span id="outbound" class="sq-button sq-button-round">外呼</span>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<div id="appo_div" style="display:none">
    <form id="appo_formSet">
        <div class="fieldset1 tabel_col tabel_col_s noBorder clearFix">
            <div class="fieldBox col_50">
                <div class="label">预约时间<span class="requiredSymbol">*</span></div>
                <div class="field">
                    <input name="appoDt" id="appoDt" type="text" class="ui-datepicker" value="${rskAppoRecVO.appoDt}"
                           validate="{required:true}">
                </div>
            </div>
        </div>
        <div class="btnsBox">
            <span id="confirmBtn" class="sq-button sq-button-round l-dialog-btn-ok">确定</span>
            <span id="cancelBtn" class="sq-button sq-button-round co_normal l-dialog-btn-cancel">取消</span>
        </div>
    </form>
</div>


<div  style="display:none">
	<div id= "configDilog" >
	   <form id="mainGoodsCd_formSet">
		<div class="fieldset1 tabel_col clearFix">
			<div class="fieldBox col_100_auto">
				<div class="label">主货物大类</div>
				<div class="field">
					<select name="mainGoodsCd" id="mainGoodsCd" data-value=" " onchange="getGoods();">
						<option value=" " checked >请选择</option>
						<c:forEach items="${mainGdsTypCdList }" var="kv">
							<option value="${kv.key }">${kv.value }</option>
						</c:forEach>
					</select>
				</div>
			</div>
			
			<div class="fieldBox col_100_auto">
				<div class="label">主运输货物</div>
				<div class="field">
					<select name="goods" id="goods" data-value=" " onchange="checkGoods();">
					</select>
				</div>
			</div>
			
		</div>
	 </form>
	</div>
</div>

<script type="text/javascript">
    var grid = null, form = null,mainGoodsCdform =null;
    $(function () {
    	mainGoodsCdform = $("#mainGoodsCd_formSet").ligerForm();
    	
        initOrgTree();
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/risk/rentRemind/initRemindList.do',
            method: 'get',
            columns: [
                {display: '客户名称', name: 'cstNm', minWidth: 200, align: 'left', enabledSort: false},
                {display: '提醒合同数', name: 'remindCntQty', width: 100, align: 'right', enabledSort: false},
                {display: '提醒支付表数', name: 'remindPayQty', width: 100, align: 'right', enabledSort: false},
                {
                    display: '应收总金额(元)', name: 'receivableTtlAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.receivableTtlAmt / 100);
                    }
                },
                {
                    display: '实收总金额(元)', name: 'receivedTtlAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.receivedTtlAmt / 100);
                    }
                },
                {
                    display: '逾期应收总金额(元)', name: 'overdueTtlAmt', width: 120, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.overdueTtlAmt / 100);
                    }
                },

                {
                    display: '操作', width: 250, align: 'left', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="repaymentDtl(' + rowdata.cstId + ',\'' + rowdata.cstNm + '\');"><i class="sqBtnIco_49"></i>还款明细</a>  ' +
                                '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="overdueDtl(' + rowdata.cstId + ');"><i class="sqBtnIco_50"></i>逾期明细</a> ' +
                                '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="qyCommRec(' + rowdata.cstId + ',\'' + rowdata.cstNm + '\');"><i class="sqBtnIco_51"></i>提醒记录</a>';
                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            frozen: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            onBeforeShowData: function () {
                var grid = this;
                grid.collapsedRows = [];
            },
            detail: {
                height: 'auto',
                onShowDetail: showDetail_grid
            }
        });
        grid.setHeight(100);

        //事业部
        $("#buOrgCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        //提醒方式
        $("#collectWayCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });

        form = $("#searchBar").ligerForm();
        liger.get("buOrgCd").setData(${buOrgCdList});

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });


        //预约
        $("#appoBtn").click(function (event) {
            var selectedRows = detailGrid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }

            $.ligerDialog.SQopen({
                width: 400,
                title: '预约',
                target: $("#appo_div")
            });
            $("#appo_formSet").ligerForm({
                validate: true
            });
        });

        $("#confirmBtn").click(function (event) {
            var ligerForm = liger.get("appo_formSet");
            if (!ligerForm.valid()) {
                $.ligerDialog.SQalert({content: "请选择预约时间！", SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = ligerForm.getData();
            var selectedRows = detailGrid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                _ids.push({'cstId': selectedRows[index].cstId, 'paySchId': selectedRows[index].paySchId});
            }
            data['ids'] = JSON.stringify(_ids);
            data['buTypCd'] = 2;//租金提醒
            $.ligerDialog.hide();

            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: '<%=path%>/risk/rskAppoRec/add.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        parent.$("#clearBtn").click();
                        parent.$("#searchBtn").click();
                        //frameElement.dialog.close();
                        $.ligerDialog.hide();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });

        $("#cancelBtn").click(function (event) {
            $.ligerDialog.hide();
        });

        //导出PDF
        $("#exportPdfBtn").click(function (event) {
            exportOverDue("pdf");
        });
        //导出Excel
        $("#exportXlsBtn").click(function (event) {
            exportOverDue("xls");
        });
        
    });

    /* 还款明细 */
    function repaymentDtl(cstId, cstNm) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 850,
            height: 500,
            title: '还款明细',
            url: '<%=path%>/capital/capOverdueInfo/toRepaymentDtl.do?cstId=' + cstId + "&cstNm=" + cstNm,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }

    /* 逾期明细 */
    function overdueDtl(cstId) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 850,
            height: 500,
            title: '逾期明细',
            url: '<%=path%>/capital/capOverdueInfo/toOverdueDtl.do?cstId=' + cstId,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }


    //逾期明细列表
    function showDetail_grid(row, detailPanel, callback) {
    	
    		 //货物种类
    		var prdTypCdSelect='select';
            var prdTypCdJSON = [];
            <c:if test="${not empty prdTypCdList}">
            prdTypCdJSON = ${prdTypCdList};
            </c:if>
            
            
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);
        detailGrid = $(gridBox).ligerGrid({
            url: '<%=path%>/risk/rentRemind/initRemindPayList.do?cstId=' + row.cstId,
            parms: getParam(),
            method: 'get',
            columns: [
                {
                    display: '支付表', name: 'paySchNo', width: 160, align: 'left',
                    render: function (rowdata, index, value) {
                        if(null != rowdata.paySchNo && rowdata.paySchNo != ''){
                            return '<a href="javascript:showPaySchNoDetail('+rowdata.prjPrdDtlId+','+rowdata.paySchId+','+rowdata.prjPrdId+','+rowdata.prjId+')"'+'class="link">'+rowdata.paySchNo+'</a>';
                        }else{
                            return "";
                        }
                    }
                },
                {
                    display: '应收款名称', name: 'feeTypCd', width: 90, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        return '第' + rowdata.payPd + '期租金';
                    }
                },
                /*{display: '可否结清', name: 'isSettled', width: 70, align: 'left'},*/
                {display: '剩余租期', name: 'remainPd', width: 70, align: 'right'},
                {display: '租期总数', name: 'payPd', width: 70, align: 'right'},
                {display: '应收日期', name: 'payDt', width: 90, align: 'left', render: renderDate},
                {display: '紧急联系人', name: 'lkMan', width: 100, align: 'left'},
                {display: '联系电话', name: 'lkTel', width: 100, align: 'left'},
                {
                    display: '应收款金额(元)', name: 'receivableAmt', width: 90, align: 'right',
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.receivableAmt / 100);
                    }
                },
                {
                    display: '实收金额(元)', name: 'receivedAmt', width: 90, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.receivedAmt / 100);
                    }
                },
                {
                    display: '逾期应收金额(元)', name: 'overdueAmt', width: 90, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.overdueAmt / 100);
                    }
                },
                {display: '预约时间', name: 'appoDt', width: 100, align: 'center', render: renderDate},
                { display: '货物种类', minWidth: 200, isEllipsis: false,
                    render: function (rowdata, index, value) {
                    	if(rowdata.prdTypCdNm==null){
                    		 rowdata.prdTypCdNm='请选择货物类型<i class="ico_flasher"></i>';
                    	}
                        var h = '<div onclick="editNotes(event, detailGrid.rows['+index+'])">'+rowdata.prdTypCdNm+'</div>';
                        return h;
                    }
                }
                /* {
                    display: '货物种类', name: 'prdTypCd', width: 150,
                    editor: {
                        type: prdTypCdSelect,
                        data: prdTypCdJSON,
                        valueField: 'key',
                        textField: 'value'
                    },
                    valueField: 'prdTypCd',
                    textField: 'prdTypCdNm',
                    render: function (item) {
                        if (StringUtils.isEmpty(item.prdTypCd)) {
                            item.prdTypCdNm = "请选择货物类型！";
                            return '请选择货物类型<i class="ico_flasher"></i>';
                        } else {
                            return item.prdTypCdNm
                        }
                    }
                } */
            ],
           /*  onBeforeSubmitEdit: function (e) {
                //验证编辑器结果是否通过 [介于编辑后未提交之前  原始数据与新数据对比]
                if (e.column.name == "prdTypCd") {
                    //原始值与选中值判断是否一致
                    //debugger;
                    if (StringUtils.isEmpty(e.value) || e.record.prdTypCd == e.value) {
                        $.ligerDialog.SQalert({content: LogUtils.LOG_CAP_FUND_TYPE_LOG, SQ_type: "warning"});
                    } else {
                        onModify(e.record.paySchId, e.value);
                    }
                }
            }, 
            enabledEdit: true,*/
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            isScroll: false,
            rownumbers: true,  //显示序号
            checkbox: true,
            allowUnSelectRow: true,
            alternatingRow: true,
            onAfterShowData: callback,
            frozen: false,
            usePager: false
        });
    }

    function getParam() {
        var data = form.getData();
        return data;
    }
    
    function editNotes(event, rowData) {
        var paySchId = rowData.paySchId;
            //$notesEdit = $('#configDilog');
        var onOk = function (item, Dialog) {
        	var goods = liger.get("goods");
        	var selectGoods = goods.getSelected();
        	if(!selectGoods){
        		  Dialog.hide();
        		  return;
        	}
        	onModify(paySchId,selectGoods.id);
        	detailGrid.updateRow(rowData,{prdTypCdNm:selectGoods.text});
            Dialog.hide();
        };
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 600,
            height: 250,
            title : '货物种类',
            target : $('#configDilog'),
            buttons: [{
                    text: "确认", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
                },
                {
                    text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
                }
            ]
        });
    }


  //主货物大类change事件
    function getGoods(){
	 
    	var _PCode = $("#mainGoodsCd").val();
    	if(!_PCode) return;
    	$.ajax({
    		type: 'post',
    		dataType:'json',
    		data:{PCode:_PCode},
    		url: '<%=path%>/audit/audCreditInfo/getGoodsTypJSON.do',
    		success:function(msg){
    			if(msg.success == 1){
    				//主运输货物
    				var goods = $("#goods");
    				if(goods.length){
    					$("#goods").empty();
    					$("#goods").append("<option value=''>请选择</option>");
    					if(msg.data==null)return;
    					$.each(msg.data,function(index,obj) {
    						var option = "<option value='"+obj.key+"'>"+obj.value+"</option>";
    							$(option).appendTo("#goods");
    							liger.get("goods").setSelect();
    					});
    					
    				}
    				SetIframe_height();
    			}else{
    				top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
    			}
    		}
    	});
    }
  
    function checkGoods(){
    	var goods = liger.get("goods");
    	if(goods){
    		var selectGoods = goods.getSelected();
    	}
    }
    
    //修改类型
    function onModify(paySchId,value) {
    
        //如果客户恶意选中 这里将拦截
        if (StringUtils.isEmpty(value)) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_OPERATE_FAIL, SQ_type: "error"});
        }
        $.ajax({
            type: 'GET',
            dataType: 'json',
            url: '<%=path%>/risk/rentRemind/modifyPrdTypCd.do?paySchId=' + paySchId + '&value=' + value,
            success: function (msg) {
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    //grid.reload($('.pcontrol input', grid.toolbar).val());//加载到当前页
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }
    
    

    //导出PDF、导出Excel
    function exportOverDue(format) {
        var form = liger.get("searchBar");
        var data = form.getData();
        var req = "format=" + format;
        for (name in data) {
            for (name in data) {
                if (data[name]) {
                    req = req + "&" + name + "=" + data[name];
                }
            }
        }
        window.location.href = "<%=path%>/capital/capOverdueInfo/exportOverdue.do?" + req;
    }

    //查询提醒记录
    function qyCommRec(_cstId, _cstNm) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.open({
            width: 1110,
            height: 500,
            title: '提醒记录',
            url: '<%=path%>/risk/rskCommRec/toListPage.do?cstId=' + _cstId + '&cstNm=' + _cstNm + '&qt=1&buTypCd=2',
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }

    function initOrgTree() {
        var params = {};
        params.cstMgrOrgCd = '${currOrg}';
        searchOrgTree = $("#cstMgrOrgCd").ligerComboBox({
            width: 480,
            selectBoxWidth: 480,
            selectBoxHeight: 150,
            //限制只能选叶节点，父节点不能点击
            treeLeafOnly: false,
            valueField: 'orgCd',
            textField: 'orgDispNm',
            showTreePath: true,
            tree: {
                ajaxType: 'get',
                idFieldName: 'orgCd',
                textFieldName: 'orgDispNm',
                checkbox: false,
                parentIcon: "none",
                childIcon: "none",
                needCancel: false
            }
        });
        $.ajax({
            type: 'get',
            dataType: 'json',
            data: params,
            url: '<%=path%>/project/prjbscinfo/searchBuOrgTree.do',
            success: function (msg) {
                if (msg.success == 1) {
                    searchOrgTree.treeManager.setData(msg.data);
                    searchOrgTree.clear();
                    searchOrgTree.setValue('${currOrg}');
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //jiangzg 2017-8-21 15:12:35 add 查看支付表明细
    function showPaySchNoDetail(prjPrdDtlId,paySchId,prjPrdId,prjId){
        var editFlag = true;
        Add_navTab('tab_prj_quat_prps'+paySchId,'查看支付表','<%=path%>/project/prjprdpayschm/toDetailPage.do?prjId='+prjId+'&&id='+paySchId+'&&prjPrdDtlId='+prjPrdDtlId+'&&prjPrdId='+prjPrdId+'&&detailFlag='+editFlag);
    }
  //外呼
    $("#outbound").click(function (event){
    	 var selectedRows = grid.getSelectedRows();
         if (selectedRows.length == 0) {
             $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
             return;
         }
         var startPayDt = $("#startPayDts").val();
         
         if(StringUtils.isEmpty(startPayDt)){
        	 $.ligerDialog.SQalert({content: "外呼 应还时间不能为空", SQ_type: "warning"});
             return;
         }
         var _ids = [];
         var data = {};
         for (var index in selectedRows) {
             _ids.push(selectedRows[index].cstId);
         }
         data['ids'] = JSON.stringify(_ids);
         data['startPayDt'] = startPayDt;
         $.ligerDialog.hide();
         var wait_dialog;
         $.ajax({
             type: 'post',
             dataType: 'json',
             data: data,
             url: '<%=path%>/risk/rentRemind/rentRemindOutboundList.do',
             beforeSend: function () {
                 wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
             },
             success: function (msg) {
                 wait_dialog.close();
                 if (msg.success == 1) {
                     $.ligerDialog.SQalert({content: "外呼成功", SQ_type: "success"});
                 } else {
                     $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                 }
             }
         });
    });

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
</script>

</body>
</html>
